package com.quarters.util;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * @program: ship-service
 * @description: order id generator utils
 * @author: zhaogaz
 * @create: 2018-05-25 10:18
 **/
public class OrderIdUtil {
    /**
     * 订单编号生成 工具
     *
     * @param startModuleCode 模块代码，长度》=2，推荐2位字母
     * @param userId          用户ID
     * @return orderId
     */
    public static String gen(String startModuleCode, Long userId) {
        startModuleCode.substring(startModuleCode.length() - 2);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String dataStr = dateFormat.format(new Date());//date 4+4+6=14
        String userStr = String.format("%020d", userId).substring(16, 20);//user 4
        String randomStr = String.format("%02d", new Random().nextInt(99));//random 2
        return startModuleCode + dataStr + userStr + randomStr;//2+14+4+2=22
    }


    /*public static String zhuan( Long userId) {
        startModuleCode.substring(startModuleCode.length() - 2);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        String dataStr = dateFormat.format(new Date());//date 4+4+6=14
        String userStr = String.format("%020d", userId).substring(16, 20);//user 4
        String randomStr = String.format("%02d", new Random().nextInt(99));//random 2
        return startModuleCode + dataStr + userStr + randomStr;//2+14+4+2=22
    }*/

    public static void main(String[] args) {

        System.out.println(gen("aa:", 1L));
    }
}
